package com.killer;

import com.killer.catalina.Catalina;
import com.killer.catalina.Lifecycle;
import com.killer.util.HttpProtocolUtil;
import com.killer.view.Request;
import org.dom4j.DocumentException;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author ：Killer
 * @date ：Created in 20-11-9 上午11:43
 * @description：${description}
 * @modified By：
 * @version: version
 */
public class Bootstrap {


    static {

    }

    /**
     * 全局维护一个Catalina的守护进程
     */
    private Catalina catalinaDaemon = null;

    public static void main(String[] args) throws IOException {

        Bootstrap bootstrap=new Bootstrap();
        bootstrap.init();

//        ServerSocket serverSocket = new ServerSocket(8080);
//        while (true) {
//
//            Socket socket = serverSocket.accept();
//
//            InputStream inputStream = socket.getInputStream();
//            Request request = new Request(inputStream);
//            System.out.println(request);
//            OutputStream outputStream = socket.getOutputStream();
//            String repData="Hello Mini Cat";
//            outputStream.write(HttpProtocolUtil.getRep200Header(repData.getBytes().length).getBytes());
//            outputStream.write(repData.getBytes());
////            outputStream.flush();
//            inputStream.close();
//            outputStream.flush();
//            socket.close();
//        }
    }

    private void init(){
        catalinaDaemon=new Catalina();
        try {
            catalinaDaemon.load();
            catalinaDaemon.start();
            System.out.println(111);
        } catch (DocumentException e) {
            throw new RuntimeException(e);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
